home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / msword1a / wbrword.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-08-27  |  18.1 KB  |  541 lines

  1. VERSION 5.00
  2. Object = "{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}#1.1#0"; "SHDOCVW.DLL"
  3. Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
  4. Begin VB.Form frmWbrWord 
  5.    Caption         =   "Word"
  6.    ClientHeight    =   3510
  7.    ClientLeft      =   60
  8.    ClientTop       =   630
  9.    ClientWidth     =   5280
  10.    MDIChild        =   -1  'True
  11.    MinButton       =   0   'False
  12.    ScaleHeight     =   3510
  13.    ScaleWidth      =   5280
  14.    Tag             =   "Word"
  15.    WindowState     =   2  'Maximized
  16.    Begin MSComctlLib.StatusBar sta 
  17.       Align           =   2  'Align Bottom
  18.       Height          =   315
  19.       Left            =   0
  20.       TabIndex        =   1
  21.       Top             =   3195
  22.       Width           =   5280
  23.       _ExtentX        =   9313
  24.       _ExtentY        =   556
  25.       Style           =   1
  26.       _Version        =   393216
  27.       BeginProperty Panels {8E3867A5-8586-11D1-B16A-00C0F0283628} 
  28.          NumPanels       =   1
  29.          BeginProperty Panel1 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
  30.          EndProperty
  31.       EndProperty
  32.    End
  33.    Begin SHDocVwCtl.WebBrowser wbr 
  34.       Height          =   2475
  35.       Left            =   360
  36.       TabIndex        =   0
  37.       Top             =   360
  38.       Width           =   4515
  39.       ExtentX         =   7964
  40.       ExtentY         =   4366
  41.       ViewMode        =   1
  42.       Offline         =   0
  43.       Silent          =   0
  44.       RegisterAsBrowser=   0
  45.       RegisterAsDropTarget=   0
  46.       AutoArrange     =   -1  'True
  47.       NoClientEdge    =   0   'False
  48.       AlignLeft       =   0   'False
  49.       ViewID          =   "{0057D0E0-3573-11CF-AE69-08002B2E1262}"
  50.       Location        =   ""
  51.    End
  52.    Begin VB.Menu mnuFileMenu 
  53.       Caption         =   "&File"
  54.       Begin VB.Menu mnuFile 
  55.          Caption         =   "&Open..."
  56.          Index           =   0
  57.       End
  58.       Begin VB.Menu mnuFile 
  59.          Caption         =   "&Close"
  60.          Index           =   1
  61.       End
  62.       Begin VB.Menu mnuFile 
  63.          Caption         =   "-"
  64.          Index           =   2
  65.       End
  66.       Begin VB.Menu mnuFile 
  67.          Caption         =   "&Save"
  68.          Index           =   3
  69.       End
  70.       Begin VB.Menu mnuFile 
  71.          Caption         =   "Save &As..."
  72.          Index           =   4
  73.       End
  74.       Begin VB.Menu mnuFile 
  75.          Caption         =   "Save as &HTML..."
  76.          Index           =   5
  77.       End
  78.       Begin VB.Menu mnuFile 
  79.          Caption         =   "-"
  80.          Index           =   6
  81.       End
  82.       Begin VB.Menu mnuFile 
  83.          Caption         =   "Page Set&up..."
  84.          Index           =   7
  85.       End
  86.       Begin VB.Menu mnuFile 
  87.          Caption         =   "&Print..."
  88.          Index           =   8
  89.          Shortcut        =   ^P
  90.       End
  91.       Begin VB.Menu mnuFile 
  92.          Caption         =   "-"
  93.          Index           =   9
  94.       End
  95.       Begin VB.Menu mnuFile 
  96.          Caption         =   "Properties"
  97.          Index           =   10
  98.          Begin VB.Menu mnuFileProps 
  99.             Caption         =   "Summary Info"
  100.             Index           =   0
  101.          End
  102.          Begin VB.Menu mnuFileProps 
  103.             Caption         =   "Word Count"
  104.             Index           =   1
  105.          End
  106.       End
  107.       Begin VB.Menu mnuFile 
  108.          Caption         =   "-"
  109.          Index           =   11
  110.       End
  111.       Begin VB.Menu mnuFile 
  112.          Caption         =   "Close &Window"
  113.          Index           =   12
  114.       End
  115.    End
  116.    Begin VB.Menu mnuViewMenu 
  117.       Caption         =   "&View"
  118.       Begin VB.Menu mnuView 
  119.          Caption         =   "Normal View"
  120.          Index           =   0
  121.       End
  122.       Begin VB.Menu mnuView 
  123.          Caption         =   "Page Layout"
  124.          Index           =   1
  125.       End
  126.       Begin VB.Menu mnuView 
  127.          Caption         =   "-"
  128.          Index           =   2
  129.       End
  130.       Begin VB.Menu mnuView 
  131.          Caption         =   "Horizontal Scroll"
  132.          Index           =   3
  133.       End
  134.       Begin VB.Menu mnuView 
  135.          Caption         =   "Ruler"
  136.          Index           =   4
  137.       End
  138.       Begin VB.Menu mnuView 
  139.          Caption         =   "Toolbars"
  140.          Index           =   5
  141.          Begin VB.Menu mnuViewToolbar 
  142.             Caption         =   "Standard"
  143.             Index           =   0
  144.          End
  145.          Begin VB.Menu mnuViewToolbar 
  146.             Caption         =   "Formatting"
  147.             Index           =   1
  148.          End
  149.          Begin VB.Menu mnuViewToolbar 
  150.             Caption         =   "Drawing"
  151.             Index           =   2
  152.          End
  153.          Begin VB.Menu mnuViewToolbar 
  154.             Caption         =   "Reviewing"
  155.             Index           =   3
  156.          End
  157.       End
  158.    End
  159.    Begin VB.Menu mnuToolsMenu 
  160.       Caption         =   "&Tools"
  161.       Begin VB.Menu mnuTools 
  162.          Caption         =   "&Spelling"
  163.          Index           =   0
  164.       End
  165.       Begin VB.Menu mnuTools 
  166.          Caption         =   "&Thesaurus..."
  167.          Index           =   1
  168.       End
  169.       Begin VB.Menu mnuTools 
  170.          Caption         =   "&Options"
  171.          Index           =   2
  172.          Begin VB.Menu mnuOpt 
  173.             Caption         =   "Show All"
  174.             Index           =   0
  175.          End
  176.          Begin VB.Menu mnuOpt 
  177.             Caption         =   "Status Bar"
  178.             Checked         =   -1  'True
  179.             Index           =   1
  180.          End
  181.       End
  182.    End
  183. Attribute VB_Name = "frmWbrWord"
  184. Attribute VB_GlobalNameSpace = False
  185. Attribute VB_Creatable = False
  186. Attribute VB_PredeclaredId = True
  187. Attribute VB_Exposed = False
  188. Option Explicit
  189. ' WbrWord.frm v1.00 (Vb6) Apr 1999  contact markb@orionstudios.com
  190. ' Uses WebBrowser Control as container for MS Word Document.
  191. ' Project/References must include:-
  192. '   Microsoft Word 8.0 Object Library (MSWord8.olb)
  193. '   Microsoft Office 8.0 Object Library (MSO97.dll)
  194. '   Microsoft Dialog Automation Objects (DlgObjs.dll)
  195. ' Note settings for the following properties (change for stand-alone form):-
  196. '   MDIChild = True
  197. '   ControlBox = False
  198. 'NB: WinWord is started when a Word document is loaded into the
  199. '    WebBrowser Control and remains active until that Control is destroyed.
  200. '    This can be confirmed using Ctrl-Alt-Del to view the task list.
  201. '=================================================================================
  202. ' Module-level Variables
  203. Private MARGINx2 As Long
  204. Private mTopUsedArea As Long    ' varies with ToolBar/Captions visibility
  205. Private mBotUsedArea As Long    ' varies with StatusBar visibility
  206. Private mVertUsedArea As Long   ' = mTopUsedArea + mBotUsedArea
  207. Private mDoc As Word.Document   ' Word Document contained by WebBrowser Control
  208. Private mDocURL As String       ' URL of Word Document contained by WebBrowser Control
  209. ' Module-level Constants
  210. Private Const MARGIN = 0        ' set as required (Twips)
  211. Private Const TITLE_HEAD = "<HEAD>" _
  212.             & "<style type='text/css'>" _
  213.             & "BODY" _
  214.             & "{color:white;" _
  215.             & "background-color:#689CD0;" _
  216.             & "font:48pt 'Comic Sans MS';" _
  217.             & "text-align:center}" _
  218.             & "</style>" _
  219.             & "</HEAD>"
  220. Private Const TITLE_BODY = "<BODY SCROLL=NO>" _
  221.             & "MS Word<BR>Document<BR>Container" _
  222.             & "</BODY>"
  223. Private Const TITLE_PAGE = "about:" & TITLE_HEAD & TITLE_BODY
  224. ' Browser navigation constants
  225. Private Const navNoHistory = 2
  226. Private Const navNoReadFromCache = 4
  227. Private Const navNoWriteToCache = 8
  228. Private Const mNavFlags = navNoHistory Or navNoReadFromCache Or navNoWriteToCache
  229. ' File Menu constants
  230. Private Const FILE_OPEN = 0
  231. Private Const FILE_CLOSE = 1
  232. Private Const FILE_SAVE = 3
  233. Private Const FILE_SAVEAS = 4
  234. Private Const FILE_SAVEASHTML = 5
  235. Private Const FILE_PAGESETUP = 7
  236. Private Const FILE_PRINT = 8
  237. Private Const FILE_PROPS = 10
  238. Private Const FILE_CLOSEWIN = 12
  239. ' Properties Menu constants
  240. Private Const PROP_SUMMARY = 0
  241. Private Const PROP_WORDCOUNT = 1
  242. ' View Menu constants
  243. Private Const VIEW_NORMAL = 0
  244. Private Const VIEW_PAGE = 1
  245. Private Const VIEW_HSCROLL = 3
  246. Private Const VIEW_RULER = 4
  247. ' Tool Menu constants
  248. Private Const TOOLS_SPELL = 0
  249. Private Const TOOLS_THESAURUS = 1
  250. Private Const TOOLS_OPTIONS = 2
  251. ' Option Menu constants
  252. Private Const OPT_SHOWALL = 0
  253. Private Const OPT_STATUSBAR = 1
  254. Private Sub Form_Load()
  255.     MARGINx2 = MARGIN * 2
  256.     mTopUsedArea = MARGIN   ' + VB toolbar height, if present
  257.     mBotUsedArea = sta.Height
  258.     mVertUsedArea = mTopUsedArea + mBotUsedArea
  259.     wbr.Navigate TITLE_PAGE, mNavFlags  ' Doco says Navigate2 not applicable to VB
  260. End Sub
  261. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  262.     If Not (mDoc Is Nothing) Then
  263.         If Not mDoc.Saved Then
  264.             Cancel = True
  265.             MsgBox "This Document has been changed." _
  266.                     & vbNewLine & vbNewLine _
  267.                     & "Please Close or Save from the File Menu.", _
  268.                     vbExclamation, App.FileDescription
  269.         End If
  270.     End If
  271. End Sub
  272. Private Sub Form_Resize()
  273.     On Error Resume Next
  274.     wbr.Move MARGIN, mTopUsedArea, Me.ScaleWidth - MARGINx2, Me.ScaleHeight - mVertUsedArea
  275. End Sub
  276. Private Sub mnuFileMenu_Click()
  277.     Dim IsWordDoc As Boolean
  278.     Dim IsSaved As Boolean
  279.     IsWordDoc = Not (mDoc Is Nothing)
  280.     If IsWordDoc Then
  281.         IsSaved = mDoc.Saved
  282.     End If
  283.     mnuFile(FILE_CLOSE) = IsWordDoc
  284.     mnuFile(FILE_SAVE) = IsWordDoc And Not IsSaved
  285.     mnuFile(FILE_SAVEAS) = IsWordDoc
  286.     mnuFile(FILE_SAVEASHTML) = IsWordDoc
  287.     mnuFile(FILE_PAGESETUP) = IsWordDoc
  288.     mnuFile(FILE_PRINT) = IsWordDoc
  289.     mnuFile(FILE_PROPS) = IsWordDoc
  290.     mnuFile(FILE_CLOSEWIN) = IsSaved Or Not IsWordDoc
  291. End Sub
  292. Private Sub mnuFile_Click(Index As Integer)
  293.     On Error Resume Next
  294.     Dim FileName As String
  295.     Select Case Index
  296.         Case FILE_OPEN
  297.             FileName = FileDlgs.GetOpenFileName( _
  298.                             App.Path, _
  299.                             "Word Documents (*.doc):*.doc", _
  300.                             "Rich Text Format (*.rtf):*.rtf")
  301.             If Len(FileName) Then
  302.                 sta.SimpleText = "Opening " & FileName & " ..."
  303.                 wbr.Navigate FileName, mNavFlags
  304.             End If
  305.             
  306.         Case FILE_CLOSE
  307.             wbr.Navigate TITLE_PAGE, mNavFlags  ' removes Word document but
  308.                                                 ' DOES NOT close Word instance
  309.         Case FILE_SAVE
  310.             wbr.ExecWB _
  311.                 cmdID:=OLECMDID_SAVE, _
  312.                 cmdexecopt:=OLECMDEXECOPT_PROMPTUSER
  313.                 
  314.         Case FILE_SAVEAS
  315.             wbr.ExecWB _
  316.                 cmdID:=OLECMDID_SAVEAS, _
  317.                 cmdexecopt:=OLECMDEXECOPT_PROMPTUSER
  318.                 
  319.         Case FILE_SAVEASHTML
  320.             FileSaveAsHTML
  321.             
  322.         Case FILE_PAGESETUP
  323.             wbr.ExecWB _
  324.                 cmdID:=OLECMDID_PAGESETUP, _
  325.                 cmdexecopt:=OLECMDEXECOPT_PROMPTUSER
  326.                 
  327.         Case FILE_PRINT
  328.             wbr.ExecWB _
  329.                 cmdID:=OLECMDID_PRINT, _
  330.                 cmdexecopt:=OLECMDEXECOPT_PROMPTUSER
  331.                 
  332.         Case FILE_CLOSEWIN
  333.             Unload Me
  334.             
  335.     End Select
  336. End Sub
  337. Private Sub mnuFileProps_Click(Index As Integer)
  338. ' See VbaWrd8.HLP for distinction between "Show" and "Display" methods
  339.     On Error Resume Next
  340.     Select Case Index
  341.         Case PROP_SUMMARY  ' Word Document Summary Info
  342.             mDoc.Application.Dialogs(wdDialogFileSummaryInfo).Show
  343.             
  344.         Case PROP_WORDCOUNT  ' Word Document Word Count (display only)
  345.             mDoc.Application.Dialogs(wdDialogToolsWordCount).Display
  346.             
  347.     End Select
  348.         
  349. End Sub
  350. Private Sub mnuViewMenu_Click()
  351.     On Error Resume Next
  352.     Dim mnu As Menu
  353.     With mDoc
  354.         With .ActiveWindow
  355.             mnuView(VIEW_NORMAL).Checked = (.View.Type = wdNormalView)
  356.             mnuView(VIEW_PAGE).Checked = (.View.Type = wdPageView)
  357.             mnuView(VIEW_HSCROLL).Checked = .DisplayHorizontalScrollBar
  358.             mnuView(VIEW_RULER).Checked = .DisplayRulers
  359.         End With
  360.         
  361.         For Each mnu In mnuViewToolbar  ' Assumes Menu captions match Toolbar names
  362.             mnu.Checked = .CommandBars(mnu.Caption).Visible
  363.         Next
  364.         
  365.     End With
  366. End Sub
  367. Private Sub mnuView_Click(Index As Integer)
  368.     On Error Resume Next
  369.     With mDoc.ActiveWindow
  370.         Select Case Index
  371.         
  372.             Case VIEW_NORMAL
  373.                 .View.Type = wdNormalView
  374.                 
  375.             Case VIEW_PAGE
  376.                 .View.Type = wdPageView
  377.                 
  378.             Case VIEW_HSCROLL
  379.                 .DisplayHorizontalScrollBar = Not .DisplayHorizontalScrollBar
  380.                 
  381.             Case VIEW_RULER
  382.                 .DisplayRulers = Not .DisplayRulers
  383.           
  384.         End Select
  385.     End With
  386. End Sub
  387. Private Sub mnuViewToolbar_Click(Index As Integer)
  388.     On Error Resume Next
  389.     Dim msoBarPos As Office.MsoBarPosition
  390.     Dim strToolbarName As String
  391.     strToolbarName = mnuViewToolbar(Index).Caption
  392.     With mDoc.CommandBars(strToolbarName)
  393.         .Enabled = True ' ToolBar must be Enabled before it can be made Visible
  394.         .Visible = Not .Visible
  395.         mnuViewToolbar(Index).Checked = .Visible
  396.         
  397.         If .Visible Then
  398.         
  399.             Select Case strToolbarName
  400.             
  401.                 Case "Drawing"
  402.                     msoBarPos = msoBarBottom
  403.                     
  404.                 Case "Reviewing"
  405.                     msoBarPos = msoBarRight
  406.                     
  407.                 Case Else
  408.                     msoBarPos = msoBarTop
  409.             End Select
  410.             
  411.             .Position = msoBarPos
  412.             
  413.         End If
  414.         
  415.     End With
  416. End Sub
  417. Private Sub mnuToolsMenu_Click()
  418.     On Error Resume Next
  419.     With mDoc
  420.         mnuTools(TOOLS_SPELL) = Not .SpellingChecked
  421.         
  422.         With .Application.Selection ' restrict to one word only
  423.             mnuTools(TOOLS_THESAURUS) = (.Type = wdSelectionNormal) _
  424.                                     And (.Words.Count = 1)
  425.         End With
  426.         
  427.     End With
  428. End Sub
  429. Private Sub mnuTools_Click(Index As Integer)
  430.     On Error Resume Next
  431.     Select Case Index
  432.         Case TOOLS_SPELL
  433.             mDoc.CheckSpelling
  434.         
  435.         Case TOOLS_THESAURUS
  436.             mDoc.Application.Selection.Range.CheckSynonyms
  437.             
  438.         Case TOOLS_OPTIONS
  439.             mnuOpt(OPT_SHOWALL).Checked = mDoc.ActiveWindow.View.ShowAll
  440.             mnuOpt(OPT_STATUSBAR).Checked = sta.Visible
  441.             
  442.     End Select
  443. End Sub
  444. Private Sub mnuOpt_Click(Index As Integer)
  445.     On Error Resume Next
  446.     Dim blnChecked As Boolean
  447.     With mnuOpt(Index)
  448.         .Checked = Not .Checked
  449.         blnChecked = .Checked
  450.     End With
  451.     Select Case Index
  452.         Case OPT_SHOWALL
  453.             mDoc.ActiveWindow.View.ShowAll = blnChecked
  454.            
  455.         Case OPT_STATUSBAR
  456.             sta.Visible = blnChecked
  457.             SetBotUsedArea
  458.             
  459.     End Select
  460. End Sub
  461. Private Sub wbr_DocumentComplete(ByVal pDisp As Object, URL As Variant)
  462.     On Error GoTo DocumentComplete_Error
  463.     If pDisp Is wbr.Object Then
  464.         mnuViewMenu = TypeOf wbr.Document Is Word.Document
  465.         mnuToolsMenu = mnuViewMenu
  466.         
  467.         If mnuViewMenu Then
  468.             Set mDoc = wbr.Document
  469.             mDocURL = URL
  470.             Me.Caption = mDocURL
  471.             sta.SimpleText = "Done"
  472.         Else
  473.             Set mDoc = Nothing
  474.             mDocURL = vbNullString
  475.             Me.Caption = Me.Tag
  476.         End If
  477.         
  478.     End If
  479. DocumentComplete_Exit:
  480.     Exit Sub
  481. DocumentComplete_Error:
  482.     MsgBox Err.Number & " - " & Err.Description, vbExclamation, _
  483.                 Me.Name & ".DocumentComplete"
  484.     Resume DocumentComplete_Exit
  485. End Sub
  486. Private Sub wbr_StatusTextChange(ByVal Text As String)
  487.     sta.SimpleText = Text
  488. End Sub
  489. Private Sub FileSaveAsHTML()
  490. ' This can also be done with the "SaveAs" option.
  491. ' Note that ConvHTML.SaveDocAsHTML could be used to convert a
  492. ' document to HTML withtout user intervention if parameters
  493. ' are provided by some other means.
  494.     On Error GoTo FileSaveAsHTML_Error
  495.     Dim FileName As String
  496.     Dim lngPos As Long
  497.     Dim strResult As String
  498.     Dim strMsg As String
  499.     Dim lngStyle As VbMsgBoxStyle
  500.     lngPos = InStrRev(mDocURL, "\", , vbTextCompare)
  501.     If lngPos Then
  502.         FileName = Mid$(mDocURL, lngPos + 1)
  503.         FileName = Split(FileName, ".")(0) & ".html"
  504.         FileName = LCase$(FileName)
  505.     End If
  506.     strResult = FileDlgs.GetSaveAsFileName( _
  507.                     FileName, _
  508.                     App.Path, _
  509.                     "HTML Document (*.htm;*.html):*.htm;*.html")
  510.                     
  511.     If Len(strResult) Then
  512.         FileName = ConvHTML.SaveDocAsHTML( _
  513.                     Doc:=mDoc, _
  514.                     NewFileName:=strResult)
  515.         If Len(FileName) Then
  516.             strMsg = mDocURL & vbNewLine & vbNewLine _
  517.                     & vbTab & "saved in HTML format as" & vbNewLine & vbNewLine _
  518.                     & FileName
  519.             lngStyle = vbInformation
  520.         Else
  521.             strMsg = "ERROR: Save operation failed"
  522.             lngStyle = vbExclamation
  523.         End If
  524.         MsgBox strMsg, lngStyle, "Save As HTML"
  525.     End If
  526. FileSaveAsHTML_Exit:
  527.     Exit Sub
  528. FileSaveAsHTML_Error:
  529.     MsgBox Err.Number & " - " & Err.Description, vbExclamation, _
  530.                 Me.Name & ".FileSaveAsHTML"
  531.     Resume FileSaveAsHTML_Exit
  532. End Sub
  533. Private Sub SetBotUsedArea()
  534.     With sta
  535.         .Refresh
  536.         mBotUsedArea = IIf(.Visible, .Height + MARGIN, MARGIN)
  537.     End With
  538.     mVertUsedArea = mTopUsedArea + mBotUsedArea
  539.     Form_Resize
  540. End Sub
  541.